// <copyright file="AuthorisationPolicyProviderCollection.cs" company="SharpSTS">
// Copyright (c) 2007, 2008 All Right Reserved, http://sharpsts.com/
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Barry Dorrans</author>
// <email>barryd@idunno.org</email>
// <date>2008-06-14</date>
// <summary>Represents a collection AuthorisationPolicy providers.</summary>

namespace SharpSTS.Providers
{
    using System;
    using System.Collections.Generic;
    using System.Configuration.Provider;

    /// <summary>
    /// A collection of AuthorisationPolicy Providers.
    /// </summary>
    internal sealed class AuthorisationPolicyProviderCollection : ProviderCollection, IEnumerable<AuthorisationPolicyProvider>
    {
        /// <summary>
        /// Gets the <see cref="AuthorisationPolicyProvider"/> with the specified name.
        /// </summary>
        /// <value>The <see cref="AuthorisationPolicyProvider"/> with the specified name</value>
        /// <param name="name">The name of the policy provider to get.</param>
        public new IAuthorisationPolicyProvider this[string name]
        {
            get
            {
                return (IAuthorisationPolicyProvider)base[name];
            }
        }

        /// <summary>
        /// Adds a provider to the collection.
        /// </summary>
        /// <param name="provider">The provider to be added.</param>
        /// <exception cref="ArgumentException">The <see cref="ProviderBase.Name"></see> of provider is null.- or -
        /// The length of the <see cref="ProviderBase.Name"></see> of provider is less than 1. - or -
        /// The type of the <paramref name="provider"/> is not of ClaimFillerProvider</exception>
        /// <exception cref="ArgumentNullException"><paramref name="provider"/> is null.</exception>
        /// <exception cref="NotSupportedException">The collection is read-only.</exception>
        /// <PermissionSet><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/></PermissionSet>
        public override void Add(ProviderBase provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            if (!(provider is AuthorisationPolicyProvider))
            {
                throw new ArgumentException("The provider parameter must be of type AuthorisationPolicyProvider.");
            }

            base.Add(provider);
        }

        #region IEnumerable<ClaimFillerProvider> Members
        /// <summary>
        /// Returns an enumerator that iterates through the collection.
        /// </summary>
        /// <returns>
        /// A <see cref="IEnumerator{T}"/> that can be used to iterate through the collection.
        /// </returns>
        public new IEnumerator<AuthorisationPolicyProvider> GetEnumerator()
        {
            return (IEnumerator<AuthorisationPolicyProvider>) base.GetEnumerator();
        }

        #endregion
    }
}
